<template>
<!--  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="货位编码" prop="locationCode">
        <el-input
          v-model="queryParams.locationCode"
          placeholder="请输入货位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货位状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择货位状态" clearable>
          <el-option
            v-for="dict in dict.type.wms_warehouse_location_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:wmsWarehouseLocation:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:wmsWarehouseLocation:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:wmsWarehouseLocation:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:wmsWarehouseLocation:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wmsWarehouseLocationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="货架编码" align="center" prop="rackCode" />
      <el-table-column label="货位编码" align="center" prop="locationCode" />
      <el-table-column label="所在层" align="center" prop="levelNum" />
      <el-table-column label="所在列" align="center" prop="columnNum" />
      <el-table-column label="最大承重(kg)" align="center" prop="maxWeight" />
      <el-table-column label="长度(mm)" align="center" prop="length" />
      <el-table-column label="宽度(mm)" align="center" prop="width" />
      <el-table-column label="高度(mm)" align="center" prop="height" />
      <el-table-column label="货位状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_warehouse_location_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:wmsWarehouseLocation:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:wmsWarehouseLocation:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    &lt;!&ndash; 添加或修改货位信息对话框 &ndash;&gt;
    <el-drawer
      :title=title
      :visible.sync="open"
      direction="rtl"
      custom-class="demo-drawer"
      ref="drawer"
      size="48%"
    >
      <div class="demo-drawer__content">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="货架编码" prop="rackId">
              <el-select v-model="form.rackId" placeholder="请选择货架编码" style="width: 50%" >
                <el-option v-for="item in this.warehouseRackSelect" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="货位编码" prop="locationCode">
              <el-input v-model="form.locationCode" placeholder="请输入货位编码" style="width: 50%"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所在层" prop="levelNum">
              <el-input v-model="form.levelNum" placeholder="请输入所在层" style="width: 50%"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所在列" prop="columnNum">
              <el-input v-model="form.columnNum" placeholder="请输入所在列" style="width: 50%"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="最大承重(kg)" prop="maxWeight">
              <el-input v-model="form.maxWeight" placeholder="请输入最大承重(kg)" style="width: 50%"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="长度(mm)" prop="length">
              <el-input v-model="form.length" placeholder="请输入长度(mm)" style="width: 50%"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="宽度(mm)" prop="width">
              <el-input v-model="form.width" placeholder="请输入宽度(mm)" style="width: 50%"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="高度(mm)" prop="height">
              <el-input v-model="form.height" placeholder="请输入高度(mm)" style="width: 50%"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="货位状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择货位状态" style="width: 50%">
            <el-option
              v-for="dict in dict.type.wms_warehouse_location_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </div>

    </el-drawer>
  </div>-->
  <div id="app">
    <div id="up_div">
      <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="货位编码" prop="locationCode">
          <el-input
            v-model="queryParams.locationCode"
            placeholder="请输入货位编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="货位状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择货位状态" clearable>
            <el-option
              v-for="dict in dict.type.wms_warehouse_location_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>


      </div>
    </div>
    <div id="down_div">
      <div class="app-container">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:wmsWarehouseLocation:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:wmsWarehouseLocation:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:wmsWarehouseLocation:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['system:wmsWarehouseLocation:export']"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      <el-table v-loading="loading" :data="wmsWarehouseLocationList" @selection-change="handleSelectionChange" stripe>
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="货架编码" align="center" prop="rackCode" />
        <el-table-column label="货位编码" align="center" prop="locationCode" />
        <el-table-column label="所在层" align="center" prop="levelNum" />
        <el-table-column label="所在列" align="center" prop="columnNum" />
        <el-table-column label="最大承重(kg)" align="center" prop="maxWeight" />
        <el-table-column label="长度(mm)" align="center" prop="length" />
        <el-table-column label="宽度(mm)" align="center" prop="width" />
        <el-table-column label="高度(mm)" align="center" prop="height" />
        <el-table-column label="货位状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.wms_warehouse_location_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:wmsWarehouseLocation:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:wmsWarehouseLocation:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      </div>
    </div>
<!--    添加或修改货位信息对话框-->
    <el-drawer
      :title=title
      :visible.sync="open"
      direction="rtl"
      custom-class="demo-drawer"
      ref="drawer"
      size="48%"
    >
      <div class="demo-drawer__content">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="货架编码" prop="rackId">
                <el-select v-model="form.rackId" placeholder="请选择货架编码" style="width: 50%" >
                  <el-option v-for="item in this.warehouseRackSelect" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="货位编码" prop="locationCode">
                <el-input v-model="form.locationCode" placeholder="请输入货位编码" style="width: 50%"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="所在层" prop="levelNum">
                <el-input v-model="form.levelNum" placeholder="请输入所在层" style="width: 50%"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="所在列" prop="columnNum">
                <el-input v-model="form.columnNum" placeholder="请输入所在列" style="width: 50%"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="最大承重(kg)" prop="maxWeight">
                <el-input v-model="form.maxWeight" placeholder="请输入最大承重(kg)" style="width: 50%"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="长度(mm)" prop="length">
                <el-input v-model="form.length" placeholder="请输入长度(mm)" style="width: 50%"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="宽度(mm)" prop="width">
                <el-input v-model="form.width" placeholder="请输入宽度(mm)" style="width: 50%"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="高度(mm)" prop="height">
                <el-input v-model="form.height" placeholder="请输入高度(mm)" style="width: 50%"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="货位状态" prop="status">
            <el-select v-model="form.status" placeholder="请选择货位状态" style="width: 50%">
              <el-option
                v-for="dict in dict.type.wms_warehouse_location_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </div>

    </el-drawer>
  </div>
</template>

<script>
import { listWmsWarehouseLocation, getWmsWarehouseLocation, delWmsWarehouseLocation, addWmsWarehouseLocation, updateWmsWarehouseLocation } from "@/api/system/wmsWarehouseLocation"
import { getWarehouseRackSelect } from "@/api/system/selectVo"

export default {
  name: "WmsWarehouseLocation",
  dicts: ['wms_warehouse_location_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      warehouseRackSelect: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 货位信息表格数据
      wmsWarehouseLocationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rackId: null,
        locationCode: null,
        levelNum: null,
        columnNum: null,
        maxWeight: null,
        length: null,
        width: null,
        height: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rackId: [
          { required: true, message: "货架编码不能为空", trigger: "blur" }
        ],
        locationCode: [
          { required: true, message: "货位编码不能为空", trigger: "blur" }
        ],
        levelNum: [
          { required: true, message: "所在层不能为空", trigger: "blur" }
        ],
        columnNum: [
          { required: true, message: "所在列不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "货位状态不能为空", trigger: "change" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询货位信息列表 */
    getList() {
      this.loading = true
      listWmsWarehouseLocation(this.queryParams).then(response => {
        this.wmsWarehouseLocationList = response.rows
        this.total = response.total
        this.loading = false
      })

      getWarehouseRackSelect().then(response => {
        this.warehouseRackSelect = response.data
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        locationId: null,
        rackId: null,
        locationCode: null,
        levelNum: null,
        columnNum: null,
        maxWeight: null,
        length: null,
        width: null,
        height: null,
        status: null,
        storageType: null,
        createTime: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.locationId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加货位信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const locationId = row.locationId || this.ids
      getWmsWarehouseLocation(locationId).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改货位信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.locationId != null) {
            updateWmsWarehouseLocation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addWmsWarehouseLocation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const locationIds = row.locationId || this.ids
      this.$modal.confirm('是否确认删除货位信息编号为"' + locationIds + '"的数据项？').then(function() {
        return delWmsWarehouseLocation(locationIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/wmsWarehouseLocation/export', {
        ...this.queryParams
      }, `wmsWarehouseLocation_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
<style>
body, html {
  margin: 0;
  padding: 0;
  height: 100%;
}

#app {
  //background-color: #f4f4f4;
  background-color: #ffffff;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 3px;
}

#up_div {
  background-color: white;
  height: 30%;
  width: 100%;
  margin-bottom: 20px; /* Space between the two divs */
  box-sizing: border-box;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border-radius: 4px; /* Optional rounded corners */
}

#down_div {
  background-color: white;
  height: 70%;
  width: 100%;
  box-sizing: border-box;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border-radius: 4px; /* Optional rounded corners */
}
</style>
